/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaConsultarEmpleadosTienda.java
 *
 * Created on Jan 20, 2009, 3:03:18 PM
 */

package com.wd.gui;

import com.wd.dominio.Empleado;
import com.wd.dominio.Tienda;
import com.wd.gui.controlparticular.ControlGuiTienda;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Johnny
 */
public class VentanaConsultarEmpleadosPorTienda extends javax.swing.JFrame {

    private ControlGui control_general;

    private ControlGuiTienda control_gui_tienda;

    private Vector<Tienda> tiendas;

    private Tienda tienda;

    private Vector<Empleado> empleados;

    /** Creates new form VentanaConsultarEmpleadosTienda */
    public VentanaConsultarEmpleadosPorTienda() {
        initComponents();
        java.net.URL url = getClass().getResource("Iconos/icon_016.png");
        java.awt.Image imagen = getToolkit().getImage(url);
        setIconImage (imagen);
        this.control_general = new ControlGui();
        this.control_gui_tienda = new ControlGuiTienda();
        this.tiendas = this.control_gui_tienda.consultarTiendas();
        this.llenarTiendas();
        if (this.jComboBox_tiendas.getSelectedIndex() != -1){
            this.jComboBox_tiendas.setSelectedIndex(0);
        }
    }

    private void llenarTiendas(){
        Vector<String> modeloComboBox = new Vector<String>();
        for (Tienda t : tiendas){
            modeloComboBox.add(t.getNombre());
        }
        this.jComboBox_tiendas.setModel(
                new DefaultComboBoxModel(modeloComboBox.toArray()));

    }

    private String selectCargo (int i) {
        switch (i) {
            case 0: return "Gerente";
            case 1: return "Regular";
            default : return "Indefinido";
        }
    }

    private String selectNivelEst (int i) {
        switch (i) {
            case 0: return "Ninguna";
            case 1: return "Primaria";
            case 2: return "Secundaria";
            case 3: return "Superior";
            default : return "Indefinido";
        }
    }

    private String selectEstadoCiv (int i) {
        switch (i) {
            case 0: return "Soltero";
            case 1: return "Casado";
            case 2: return "Divoricido";
            case 3: return "Viduo";
            default : return "Indefinido";
        }
    }

    private void llenarTabla(){
        DefaultTableModel dm = new DefaultTableModel();
            dm.addColumn("Cedula");
            dm.addColumn("Apellido");
            dm.addColumn("Nombre");
            dm.addColumn("Sexo");
            dm.addColumn("Fecha de Nacimiento");
            dm.addColumn("Estado Civil");
            dm.addColumn("Nivel Estudios");
            dm.addColumn("Telefono");
            dm.addColumn("Ciudad");
            dm.addColumn("Direccion");
            dm.addColumn("Cargo");

            for (Empleado e : this.empleados){
                Vector info = new Vector();
                info.addElement(e.getCedula());
                info.addElement(e.getApellido());
                info.addElement(e.getNombre());
                info.addElement(e.getSexo());
                info.addElement(e.getFechaNacimiento().toString());
                info.addElement(this.selectEstadoCiv(e.getEstadoCivil()));
                info.addElement(this.selectNivelEst(e.getNivelEstudios()));
                info.addElement(e.getTelefono());
                info.addElement(e.getCiudadVive());
                info.addElement(e.getDireccion());
                info.addElement(this.selectCargo(e.getTipo()));
                dm.addRow(info);
            }

            this.jTable1.setModel(dm);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel22 = new javax.swing.JPanel();
        jComboBox_tiendas = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Consultar Personal de Una Tienda");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Personal de Tienda"));

        jPanel22.setBorder(javax.swing.BorderFactory.createTitledBorder("Seleccione una Tienda"));

        jComboBox_tiendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_tiendassActionPerformed(evt);
            }
        });

        jLabel11.setText("Tiendas");

        javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
        jPanel22.setLayout(jPanel22Layout);
        jPanel22Layout.setHorizontalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel22Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                .addComponent(jComboBox_tiendas, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel22Layout.setVerticalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel22Layout.createSequentialGroup()
                .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox_tiendas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Personal"));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 871, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButton1.setText("Cerrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox_tiendassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_tiendassActionPerformed
        this.tienda = this.tiendas.get(this.jComboBox_tiendas.getSelectedIndex());
        this.empleados = this.control_gui_tienda.traerEmpleadosPorTienda(this.tienda.getCodigo());
        this.llenarTabla();
}//GEN-LAST:event_jComboBox_tiendassActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaConsultarEmpleadosPorTienda().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox_tiendas;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
